//
//  YBAssetsDetailResultViewController+LayoutConstraints.m
//  Nectar
//
//  Created by famer on 2023/11/12.
//  Copyright © 2023 asance. All rights reserved.
//

#import "YBAssetsDetailResultViewController+LayoutConstraints.h"

@implementation YBAssetsDetailResultViewController (LayoutConstraints)

- (void)setLayoutConstraints{
    CGFloat width = self.view.size.width;
    CGFloat height = self.view.size.height;
    CGFloat leftMargin = 16;
    CGFloat topMargin = 16;
    
    self.navigationBar.frame = CGRectMake(0,  [UIView statusBarHeight], width, 64);
    
    self.contentView.frame = CGRectMake(0,
                                        self.navigationBar.bottom,
                                        width,
                                        self.view.height-self.navigationBar.bottom);
    
    self.statusImageView.frame = CGRectMake(0, 26, 60, 60);
    self.statusImageView.centerX = self.contentView.width*0.5;
    
    CGSize statusLabelSize = [self.statusLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.statusLabel.frame = CGRectMake(0,
                                        self.statusImageView.bottom+10,
                                        self.contentView.width,
                                        statusLabelSize.height);
    
    CGSize dateLabelSize = [self.dateLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.dateLabel.frame = CGRectMake(0,
                                      self.statusLabel.bottom+6,
                                      self.contentView.width,
                                      dateLabelSize.height);
    
    ///
    self.detailContentView.frame = CGRectMake(0,
                                              self.dateLabel.bottom+26,
                                              self.contentView.width,
                                              0);
    
    CGSize detailLabelSize = [self.detailLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.detailLabel.frame = CGRectMake(leftMargin,
                                        topMargin,
                                        80,
                                        detailLabelSize.height);
    
    CGSize receiveLabelSize = [self.receiveLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.receiveLabel.frame = CGRectMake(self.detailLabel.right,
                                         topMargin,
                                         receiveLabelSize.width,
                                         receiveLabelSize.height);
    
    self.detailLabel.centerY = self.receiveLabel.centerY;
    
    CGSize receiveAmountLabelSize = [self.receiveAmountLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.receiveAmountLabel.frame = CGRectMake(self.receiveLabel.left,
                                               self.receiveLabel.bottom+8,
                                               receiveAmountLabelSize.width,
                                               receiveAmountLabelSize.height);
    
    CGSize receiveTipsLabelSize = [self.receiveTipsLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.receiveTipsLabel.frame = CGRectMake(self.receiveAmountLabel.left,
                                             self.receiveAmountLabel.bottom+8,
                                             receiveTipsLabelSize.width,
                                             receiveTipsLabelSize.height);
    
    
    self.receiveTipsImageView.frame = CGRectMake(self.detailContentView.width-leftMargin-26,
                                                 0,
                                                 26,
                                                 26);
    
    self.detailContentView.height = self.receiveTipsLabel.bottom+topMargin;
    self.receiveTipsImageView.centerY = self.detailContentView.height*0.5;
    
    
    ///
    self.transferContentView.frame = CGRectMake(0,
                                                self.detailContentView.bottom+12,
                                                self.contentView.width,
                                                0);
    
    self.fromLabel.frame = CGRectMake(leftMargin,
                                      topMargin,
                                      80,
                                      detailLabelSize.height);
    
    CGSize fromValueLabelSize = [self.fromValueLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.fromValueLabel.frame = CGRectMake(self.fromLabel.right,
                                           topMargin,
                                           fromValueLabelSize.width,
                                           fromValueLabelSize.height);
    
    self.fromLabel.centerY = self.fromValueLabel.centerY;
    
    
    if(self.fromLabel.isHidden){
        self.toLabel.frame = CGRectMake(leftMargin,
                                        topMargin,
                                        80,
                                        detailLabelSize.height);
        
        CGSize toValueLabelSize = [self.toValueLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
        self.toValueLabel.frame = CGRectMake(self.toLabel.right,
                                             topMargin,
                                             toValueLabelSize.width,
                                             toValueLabelSize.height);
        
        self.toLabel.centerY = self.toValueLabel.centerY;
                
    } else{
        self.toLabel.frame = CGRectMake(self.fromLabel.left,
                                        self.fromLabel.bottom+8,
                                        80,
                                        detailLabelSize.height);
        
        CGSize toValueLabelSize = [self.toValueLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
        self.toValueLabel.frame = CGRectMake(self.toLabel.right,
                                             self.fromLabel.bottom+8,
                                             toValueLabelSize.width,
                                             toValueLabelSize.height);
        
        self.toLabel.centerY = self.toValueLabel.centerY;
    }
    
    self.transferContentView.height = self.toValueLabel.bottom+topMargin;

    if(self.toValueLabel.isHidden){
        self.transferContentView.height = self.fromValueLabel.bottom+topMargin;
    }
    
    ///
    self.txidContentView.frame = CGRectMake(0,
                                            self.transferContentView.bottom+12,
                                            self.contentView.width,
                                            0);
    
    self.txidLabel.frame = CGRectMake(leftMargin,
                                      topMargin,
                                      80,
                                      detailLabelSize.height);
    
    CGSize txidValueLabelSize = [self.txidValueLabel textBoundingSizeWithMaxSize:CGSizeMake(width, 500)];
    self.txidValueLabel.frame = CGRectMake(self.txidLabel.right,
                                           topMargin,
                                           txidValueLabelSize.width,
                                           txidValueLabelSize.height);
    
    self.txidLabel.centerY = self.txidValueLabel.centerY;
    
    self.txidContentView.height = self.txidValueLabel.bottom+topMargin;
    
}
@end
